package com.ssh.dao;

        import com.ssh.domain.User;
        import org.hibernate.Session;
        import org.hibernate.SessionFactory;
        import org.springframework.stereotype.Component;
        import org.springframework.stereotype.Repository;

        import javax.annotation.Resource;
        import java.util.List;

@Component
public class UserDao {
    @Resource
    private SessionFactory sessionFactory;

    public SessionFactory getSessionFactory() {
        return sessionFactory;
    }

    public void setSessionFactory(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
    }

    /**
     * 查询所有
     *
     * @return
     */
    public List<User> getUsers() {
        return sessionFactory.getCurrentSession().createCriteria(User.class).list();
    }

    public void addUser(User user) {
        sessionFactory.getCurrentSession().save(user);
    }
}